package cn.opopopo.design_pattern_learn.行为型.interpreter;

// 变量：如 x, y
class VariableExpression implements Expression {
    private final String name;

    public VariableExpression(String name) {
        this.name = name;
    }

    @Override
    public boolean interpret(java.util.Map<String, Boolean> context) {
        Boolean value = context.get(name);
        if (value == null) {
            throw new IllegalArgumentException("变量未定义: " + name);
        }
        return value;
    }

    @Override
    public String toString() {
        return name;
    }
}